<script>
$(function(){
    $("#yearSemester, #select-grade").change(function(){
        $.each($(".selectTable INPUT[type='checkbox']"),function(){
            $(this).attr('checked', false);
        });
        $("#selectForm").submit();
    });
    $("#stage").change(function(){
    	$("#selectForm").submit();
    });

    $("#beginButton").click(function(){
        $("INPUT[name='act']").val('count');
    	$("#selectForm").submit();
     });
    $(".showTable tbody tr:odd").addClass('odd');
    $(".showTable tbody tr:even").addClass('even');
});
</script>
<style>
.selectTable {float: left; margin:3px; background:#eef }
.selectTable tbody tr {background: #ffe}
.showTable {background: #dff; border:2px solid #aac; border-collapse: collapse;}
.showTable td, .showTable th {padding:3px; border:thin solid #ccc; text-align:center}
.showTable th {width:40px}
.startTr td {border-top: solid #aac 2px; }
</style>
<div class="ui-widget">
<form method="post" action="" id="selectForm">
<div>
<select name="yearSemester" id="yearSemester">
<?php echo $this->YearSemesterOptions($this->yearSemester,array('order'=>'year DESC'))?>
</select>
<select id="select-grade" name="select-grade">
<option value=""><?php echo $this->translate('select grade ..')?></option>
<?php echo $this->ClassGradeOptions($this->selectGrade)?>
</select>
<?php if ($this->examineSet):?>
<select name="stage" id="stage">
<option value=""><?php echo $this->translate('choose stage ..')?></option>
<?php for($i=1; $i <= $this->examineSet->period; $i++):?>
<option value="<?php echo $i?>" <?php if($i==$this->stage):?>selected<?php endif?> ><?php echo sprintf($this->translate('%dth stage'),$i)?></option>
<?php endfor;?>
<option value="255" <?php if($this->stage==255):?>selected<?php endif?>><?php echo $this->translate('whole stage')?></option>
</select>
<input type="checkbox" id="plusCount"  name="plusCount" value="1" <?php  Sfs_Html::printChecked($this->plusCount)?>><label for="plusCount"><?php echo $this->translate('usually score counted')?></label>
<?php endif?>
</div>

<?php if ($this->subject):?>
<!--學科資料-->
<table id="selectTable" class="selectTable" >
<thead>
<tr>
<th><?php echo $this->translate('choose')?></th>
<th><?php echo $this->translate('subject name')?></th>
</tr>
</thead>
<tbody>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row):?>
<tr>
<td><input type="checkbox"  id="subject_<?php echo $row['subject_sn']?>"  name="selSubject[<?php echo $row['subject_sn']?>]" value="1"
<?php if(count($this->selSubject)==0 or isset($this->selSubject[$row['subject_sn']]))Sfs_Html::printChecked(1)?>
/></td>
<td><label for="subject_<?php echo $row['subject_sn']?>"><?php echo $row['name']?></label></td>
</tr>
<?php endforeach?>
<?php endforeach?>
</tbody>
</table>
<!--班級資料-->
<table class="selectTable">
<thead>
<tr>
<th><?php echo $this->translate('choose')?></th>
<th><?php echo $this->translate('class name')?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->className as $row):?>
<?php foreach ($row as $key=>$val):?>
<tr>
<td><input type="checkbox"  id="class_<?php echo $key?>"  name="selClass[<?php echo $key?>]" value="1"
<?php if(count($this->selClass)==0 or isset($this->selClass[$key]))Sfs_Html::printChecked(1)?>
/></td>
<td><label for="class_<?php echo $key?>"><?php echo $val?></label></td>
</tr>
<?php endforeach?>
<?php endforeach?>
</tbody>
</table>
<!--處理按鍵-->
<table class="selectTable">
<tr>
<td>
<input type="checkbox" id="showRank"  name="showRank" value="1"  <?php if ($this->showRank) Sfs_Html::printChecked(1)?> >
<label for="showRank"><?php echo $this->translate('show rank')?></label>
</td>
</tr>
<tr>
<td>
<input type="button" id="beginButton" value="<?php echo $this->translate('start count')?>" />
</td>
</tr>
</table>
<?php if ($this->averageList):?>
<!--顯示結果-->
<table class="selectTable showTable">
<thead>
<tr>
<th colspan="2"><?php echo $this->translate('class name')?></th>
<?php foreach($this->subject as $val):?>
<?php foreach($val as $row):?>
<?php if(count($this->selSubject)==0 or isset($this->selSubject[$row['subject_sn']])):?>
<th><?php echo $row['name']?></th>
<?php endif?>
<?php endforeach?>
<?php endforeach?>
<th><?php echo $this->translate('total score')?></th>
</tr>
</thead>
<tbody>
<?php $tempArr = array_pop($this->className)?>
<?php foreach ($this->selClass as $classSn=>$tt):?>
<?php $tempClass = explode('-', $classSn); $ckey = $tempClass[1];?>
<tr class="startTr">
<td rowspan="<?php if ($this->showRank) echo 3; else echo 2;?>"><?php echo $tempArr[$classSn]?></td>
<td><?php echo $this->translate('average')?></td>
<?php foreach($this->selSubject as $key=>$sval):?>
<td><?php if (isset($this->averageList[$ckey][$key]['avg'])) echo $this->averageList[$ckey][$key]['avg']?></td>
<?php endforeach?>
<td><?php if (isset($this->averageList[$ckey]['total']))echo $this->averageList[$ckey]['total']?></td>
</tr>
<tr>
<td><?php echo $this->translate('student numbers')?></td>
<?php foreach($this->selSubject as $key=>$sval):?>
<td><?php if (isset($this->averageList[$ckey][$key]['count']))echo $this->averageList[$ckey][$key]['count']?></td>
<?php endforeach?>
<td>-</td>
</tr>
<?php if ($this->showRank):?>
<tr>
<td><?php echo $this->translate('rank')?></td>
<?php foreach($this->selSubject as $key=>$sval):?>
<td><?php if(isset($this->averageList[$ckey][$key]['rank']))echo $this->averageList[$ckey][$key]['rank']?></td>
<?php endforeach?>
<td><?php if(isset($this->averageList[$ckey]['rank']))echo $this->averageList[$ckey]['rank']?></td>
</tr>
<?php endif?>

<?php endforeach?>
</tbody>
</table>
<?php endif?>

<?php endif?>
<input type="hidden" name="act" />
</form>
</div>
<div class="ui-helper-clearfix"></div>